#Twisted Shootout
#Copyright (C) 2007  Han Dao
#
#This program is free software: you can redistribute it and/or modify
#it under the terms of the GNU General Public License as published by
#the Free Software Foundation, either version 3 of the License, or
#(at your option) any later version.
#
#This program is distributed in the hope that it will be useful,
#but WITHOUT ANY WARRANTY; without even the implied warranty of
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#GNU General Public License for more details.
#
#You should have received a copy of the GNU General Public License
#along with this program.  If not, see <http://www.gnu.org/licenses/>.

#You can contact the author at wikipediankiba@gmail.com
import pygame
import data
import playeranim
class Player(pygame.sprite.Sprite):
	def __init__(self,sprites,w):
		pygame.sprite.Sprite.__init__(self)
		self.sprites = sprites
		self.w = w
		self.name, self.image = data.read.load('player')
		self.rect = self.image.get_rect()
		self.rect.x = 0
		self.rect.y = 0
		self.health = 30
		self.status = False
		self.melee = False
		self.x = 0
		self.y = 0
		self.retainer = [self.rect.x,self.rect.y]
		self.win = False
		self.keystate = 1
		self.active = False
		self.reload = 0
		self.sprites.add(self)
		self.anim = playeranim.PlayerAnim(self)
	def move(self):
		self.rect.x = self.rect.x + self.x
		self.jump()
	def execute(self):
		self.move()
		self.shoot()
		self.anim.execute()
	def jump(self):
		if self.status == True:
			self.rect.y = self.rect.y - 5
			self.y = self.y - 5
			if self.y == -100:
				self.status = 10
			self.anim.booston()
		elif self.status == 10:
			self.anim.boostoff()
			self.y = self.y + 5
			if self.y == 0:
				self.status = False
	def up(self):
		if self.status == True:
			return
		elif self.status == 10:
			return
		self.status = True
	def knife(self):
		if self.melee == False:
			self.melee = True
			self.anim.melee()
		elif self.melee == True:
			self.melee = False
			self.anim.normal()
		#Deal with which direction that the knife version should be in.
		if self.keystate == 2:
			self.image = pygame.transform.flip(self.image, True, False)
	#move left
	def left(self):
		self.act = False
		self.x = -10
	#move right
	def right(self):
		self.act = True
		self.x = 10
	def zero(self):
		self.x = 0
	def upright(self):
		if self.act != False:
			self.zero()
	def upleft(self):
		if self.act != True:
			self.zero()
	#Determine whether or not to shoot and as well figuring out what direction the bullet should go
	def shoot(self):
		if self.melee != True:
			if self.active == True:
				if self.reload == 5:
					y = self.rect.y
					if self.w.x == 10:
						x = self.rect.x + 20
					elif self.w.x == -10:
						x = self.rect.x - 40
					item = self.w.shoot(x,y)
					if item != False:
						self.sprites.add(item)
					self.reload = 0
				elif self.reload != 5:
					self.reload = self.reload + 1
	def activate(self):
		self.active = True
	def deactivate(self):
		self.active = False
	#method flipright and flipleft are concerned with the direction that the player is facing. It also determine the weapon's trajectory.
	def flipright(self):
		if self.keystate == 2:
			self.keystate = 1
			self.w.x = 10
			self.anim.imageload()
	def flipleft(self):
		if self.keystate == 1:
			self.keystate = 2
			self.w.x = -10
			self.image = pygame.transform.flip(self.image, True, False)
	def changelocation(self,n):
		self.rect.x = n[0]
		self.rect.y = n[1]